<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 系统编码管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/public.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/index.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>	
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/codeService.js"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<%@include file="/WEB-INF/jsp/include/left.jsp"%>	

	<!--right begin-->
    <div class="fl right">
 
 			<div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>系统编码快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>                
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/codeList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>编码类型：                </td>
                <td><input size="25" class="input" type="text" name="codeType" value="${searchCond.codeType}"/>
                </td>
                <td>编码名称：</td>
                <td><input size="25" class="input" type="text" name=codeName value="${searchCond.codeName}"/></td>
                <td>
                	<input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" />
                </td>
              </tr>
            </table>
            </form>
      </div>
      
    		<!--人员分配 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>系统编码</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <tr>
                    <th width="10%" align="center"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="30%">编码类型</th>
                    <th width="30%"> 编码名称</th>
                    <th width="30%">排序</th>                    
                  </tr>
                </table>
              </div>
                <div class="list">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <c:forEach var="code" items="${codeList}">
                  <tr>
                    <td width="10%" align="center"><input type="checkbox" value="${code.id}" name="id" /></td>
                    <td width="30%">${code.codeType}</td>
                    <td width="30%" align="center">${code.codeName}</td>
                    <td width="30%" align="center">${code.codeSort }</td>
                  </tr>
                  </c:forEach>
              </table>
              </div>
            </div>
            <!--人员分配 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount} </strong> 条                
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
				</div>
                <div class="fr Operating">             
                    <ul>
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addCode()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editCodes()"/></li>
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        
                    </ul>
                </div>
            </div>
 
            <!--统计 end-->
            
    </div>
	<!--right end-->
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<form>
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">编码类型：</th><td>
			<input type="text" name="codeType0" id="codeType0" value="" style="display:none"/>
			<select id="codeType1" style="display:show">
			<c:forEach var="codeType" items="${codeType}"><option value="${codeType.codeType}">${codeType.codeType}</option></c:forEach>
			</select>
			<input type="hidden" name="codeId0" id="codeId0" /></td>
			<th width="80">编码名称：</th><td><input type="text" name="codeName0" id="codeName0" value=""/> </td>
		</tr>
		<tr><th width="100">编码排序：</th><td>
			<input type="text" name="codeSort0" id="codeSort0" value="0"/>
			</td>
			<th width="80">添加新类别：</th><td>
			<input type="checkbox" id="isnew" name="isnew" onclick="isNew()"/></td>
		</tr>
		<tr><td colspan="2" style="text-align:right;height:">			
			<input type="button" value=" 提 交 " class="btn1" onclick="submitCode()"/></td>
			<td colspan="2" style="text-align:left;height:"><input type="reset" value=" 重置 " class="btn1" value="reset"/></td>
		</tr>
	</table>
	</form>
	</div>
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>
<script  type="text/javascript">
function isNew(){
	if($('isnew').checked){
		$('codeType1').style.display="none";
		$('codeType0').style.display="";
	}else{
		$('codeType1').style.display="";
		$('codeType0').style.display="none";
	}
}
function addCode(){
	WIN.show('<font size=5>添加系统编码</font>',$('winCon_1'),{width:600,height:200});
}

function delsellMultiple(){			
	var objs = document.getElementsByName("id");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			codeService.deleteCodeByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}

function editCodes(){
	var objs = document.getElementsByName("id");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editCode(vas);
	}	
}
function editCode(id){
	WIN.show('<font size=5>修改系统编码</font>',$('winCon_1'),{width:600,height:200});
	codeService.getCodeById(id,function(data){
		$('codeId0').value=data.id;
		$('codeType1').value=data.codeType;
		$('codeName0').value=data.codeName;
		$('codeSort0').value=data.codeSort;
	})
	$('isnew').style.display='none';
}
function delCode(id){
	if(confirm("删除系统编码，确定删除 ？")){
		WIN.showpg();
		codeService.deleteCode(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}

function submitCode(){	
	var data={
		id	:		$('codeId0').value,
		codeType:	$('isnew').checked?$('codeType0').value:$('codeType1').value,
		codeName:   $('codeName0').value,
		codeSort:   $('codeSort0').value
	}

	if(''==data.codeType){
		alert('编码类型不能为空');return;
	}
	if(''==data.codeName){
		alert('名称不能为空');return;
	}
	if(''==data.id){
		submitCode.data=data;
		codeService.existsCode(data.codeType.trim(),data.codeName.trim(),{
			callback:function(f){if(f){alert('此编码类型和值已经存在，请更改！');}else{submit(submitCode.data);}},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");reload();},
			errorHander:function(err){}
		})
	}else{
		
		submit(data);
	}
}
function submit(data){
	WIN.close();
	WIN.showpg();
	codeService.editCode(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
